package com.example.mymusicdisplay.data;

import android.graphics.Bitmap;
import android.os.Parcel;
import android.os.Parcelable;

/**
 * author: ts
 * created on: 2021/10/8 下午3:13
 * description:
 */
public class MusicData implements Parcelable {
    /**
     * 标题
     */
    private String mTitle;
    /**
     * 歌手
     */
    private String mSinger;
    /**
     * 专辑
     */
    private String mAlbum;
    /**
     * 歌曲地址
     */
    private String mUrl;
    /**
     * 歌曲名称
     */
    private String mSingName;
    /**
     * 歌曲播放量
     */
    private String mPlayedCount;
    /**
     * 封面图片
     */
    private String mCoverUrl;
    /**
     * 本地封面
     */
    private Bitmap mLocalCover;
    /**
     * 总时长
     */
    private long mDuration;
    /**
     * 文件大小
     */
    private long mSize;
    /**
     * 歌曲ID
     */
    private Integer mSingId;
    /**
     * 专辑ID
     */
    private Integer mAlbumId;

    /**
     * 收藏
     */
    private boolean mFavorite;

    /**
     * 是否选中
     */
    private boolean mSelected;

    public MusicData() {
    }

    protected MusicData(Parcel in) {
        mTitle = in.readString();
        mSinger = in.readString();
        mAlbum = in.readString();
        mUrl = in.readString();
        mSingName = in.readString();
        mPlayedCount = in.readString();
        mCoverUrl = in.readString();
        mLocalCover = in.readParcelable(Bitmap.class.getClassLoader());
        mDuration = in.readLong();
        mSize = in.readLong();
        if (in.readByte() == 0) {
            mSingId = null;
        } else {
            mSingId = in.readInt();
        }
        if (in.readByte() == 0) {
            mAlbumId = null;
        } else {
            mAlbumId = in.readInt();
        }
        mFavorite = in.readByte() != 0;
        mSelected = in.readByte() != 0;
    }

    public static final Creator<MusicData> CREATOR = new Creator<MusicData>() {
        @Override
        public MusicData createFromParcel(Parcel in) {
            return new MusicData(in);
        }

        @Override
        public MusicData[] newArray(int size) {
            return new MusicData[size];
        }
    };

    public String getTitle() {
        return mTitle;
    }

    public void setTitle(String title) {
        mTitle = title;
    }

    public String getSinger() {
        return mSinger;
    }

    public void setSinger(String singer) {
        mSinger = singer;
    }

    public String getAlbum() {
        return mAlbum;
    }

    public void setAlbum(String album) {
        mAlbum = album;
    }

    public String getUrl() {
        return mUrl;
    }

    public void setUrl(String url) {
        mUrl = url;
    }

    public String getSingName() {
        return mSingName;
    }

    public void setSingName(String singName) {
        mSingName = singName;
    }

    public String getPlayedCount() {
        return mPlayedCount;
    }

    public void setPlayedCount(String playedCount) {
        mPlayedCount = playedCount;
    }

    public String getCoverUrl() {
        return mCoverUrl;
    }

    public void setCoverUrl(String coverUrl) {
        mCoverUrl = coverUrl;
    }

    public Bitmap getLocalCover() {
        return mLocalCover;
    }

    public void setLocalCover(Bitmap localCover) {
        mLocalCover = localCover;
    }

    public long getDuration() {
        return mDuration;
    }

    public void setDuration(long duration) {
        mDuration = duration;
    }

    public long getSize() {
        return mSize;
    }

    public void setSize(long size) {
        mSize = size;
    }

    public Integer getSingId() {
        return mSingId;
    }

    public void setSingId(Integer singId) {
        mSingId = singId;
    }

    public Integer getAlbumId() {
        return mAlbumId;
    }

    public void setAlbumId(Integer albumId) {
        mAlbumId = albumId;
    }

    public boolean isFavorite() {
        return mFavorite;
    }

    public void setFavorite(boolean favorite) {
        mFavorite = favorite;
    }

    public boolean isSelected() {
        return mSelected;
    }

    public void setSelected(boolean selected) {
        mSelected = selected;
    }

    @Override
    public String toString() {
        return "MusicData{" +
            "mTitle='" + mTitle + '\'' +
            ", mSinger='" + mSinger + '\'' +
            ", mAlbum='" + mAlbum + '\'' +
            ", mUrl='" + mUrl + '\'' +
            ", mSingName='" + mSingName + '\'' +
            ", mPlayedCount='" + mPlayedCount + '\'' +
            ", mCoverUrl='" + mCoverUrl + '\'' +
            ", mLocalCover=" + mLocalCover +
            ", mDuration=" + mDuration +
            ", mSize=" + mSize +
            ", mSingId=" + mSingId +
            ", mAlbumId=" + mAlbumId +
            ", mFavorite=" + mFavorite +
            ", mSelected=" + mSelected +
            '}';
    }

    @Override
    public int describeContents() {
        return 0;
    }

    @Override
    public void writeToParcel(Parcel parcel, int i) {
        parcel.writeString(mTitle);
        parcel.writeString(mSinger);
        parcel.writeString(mAlbum);
        parcel.writeString(mUrl);
        parcel.writeString(mSingName);
        parcel.writeString(mPlayedCount);
        parcel.writeString(mCoverUrl);
        parcel.writeParcelable(mLocalCover, i);
        parcel.writeLong(mDuration);
        parcel.writeLong(mSize);
        if (mSingId == null) {
            parcel.writeByte((byte) 0);
        } else {
            parcel.writeByte((byte) 1);
            parcel.writeInt(mSingId);
        }
        if (mAlbumId == null) {
            parcel.writeByte((byte) 0);
        } else {
            parcel.writeByte((byte) 1);
            parcel.writeInt(mAlbumId);
        }
        parcel.writeByte((byte) (mFavorite ? 1 : 0));
        parcel.writeByte((byte) (mSelected ? 1 : 0));
    }
}
